package cn.stronglink.assetmanage.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;

import org.greenrobot.greendao.AbstractDaoMaster;
import org.greenrobot.greendao.database.StandardDatabase;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseOpenHelper;
import org.greenrobot.greendao.identityscope.IdentityScopeType;


// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
 * Master of DAO (schema version 4): knows all DAOs.
 */
public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 4;

    /** Creates underlying database table using DAOs. */
    public static void createAllTables(Database db, boolean ifNotExists) {
        RoomDao.createTable(db, ifNotExists);
        AssetDao.createTable(db, ifNotExists);
        TypeDao.createTable(db, ifNotExists);
        PatrolDetailDao.createTable(db, ifNotExists);
        DataCenterDao.createTable(db, ifNotExists);
        CabinetDao.createTable(db, ifNotExists);
        SearchAssetDao.createTable(db, ifNotExists);
        InventoryDao.createTable(db, ifNotExists);
        DepartmentDao.createTable(db, ifNotExists);
        UserDao.createTable(db, ifNotExists);
        CheckDao.createTable(db, ifNotExists);
        SyncContentDao.createTable(db, ifNotExists);
        RepairDao.createTable(db, ifNotExists);
        TaskDao.createTable(db, ifNotExists);
        RepailDetailDao.createTable(db, ifNotExists);
        PatrolDao.createTable(db, ifNotExists);
        SyncTypesDao.createTable(db, ifNotExists);
        ServerIpDao.createTable(db, ifNotExists);
        BrandDao.createTable(db, ifNotExists);
        ModelDao.createTable(db, ifNotExists);
        InventoryDetailDao.createTable(db, ifNotExists);
    }

    /** Drops underlying database table using DAOs. */
    public static void dropAllTables(Database db, boolean ifExists) {
        RoomDao.dropTable(db, ifExists);
        AssetDao.dropTable(db, ifExists);
        TypeDao.dropTable(db, ifExists);
        PatrolDetailDao.dropTable(db, ifExists);
        DataCenterDao.dropTable(db, ifExists);
        CabinetDao.dropTable(db, ifExists);
        SearchAssetDao.dropTable(db, ifExists);
        InventoryDao.dropTable(db, ifExists);
        DepartmentDao.dropTable(db, ifExists);
        UserDao.dropTable(db, ifExists);
        CheckDao.dropTable(db, ifExists);
        SyncContentDao.dropTable(db, ifExists);
        RepairDao.dropTable(db, ifExists);
        TaskDao.dropTable(db, ifExists);
        RepailDetailDao.dropTable(db, ifExists);
        PatrolDao.dropTable(db, ifExists);
        SyncTypesDao.dropTable(db, ifExists);
        ServerIpDao.dropTable(db, ifExists);
        BrandDao.dropTable(db, ifExists);
        ModelDao.dropTable(db, ifExists);
        InventoryDetailDao.dropTable(db, ifExists);
    }

    /**
     * WARNING: Drops all table on Upgrade! Use only during development.
     * Convenience method using a {@link DevOpenHelper}.
     */
    public static DaoSession newDevSession(Context context, String name) {
        Database db = new DevOpenHelper(context, name).getWritableDb();
        DaoMaster daoMaster = new DaoMaster(db);
        return daoMaster.newSession();
    }

    public DaoMaster(SQLiteDatabase db) {
        this(new StandardDatabase(db));
    }

    public DaoMaster(Database db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(RoomDao.class);
        registerDaoClass(AssetDao.class);
        registerDaoClass(TypeDao.class);
        registerDaoClass(PatrolDetailDao.class);
        registerDaoClass(DataCenterDao.class);
        registerDaoClass(CabinetDao.class);
        registerDaoClass(SearchAssetDao.class);
        registerDaoClass(InventoryDao.class);
        registerDaoClass(DepartmentDao.class);
        registerDaoClass(UserDao.class);
        registerDaoClass(CheckDao.class);
        registerDaoClass(SyncContentDao.class);
        registerDaoClass(RepairDao.class);
        registerDaoClass(TaskDao.class);
        registerDaoClass(RepailDetailDao.class);
        registerDaoClass(PatrolDao.class);
        registerDaoClass(SyncTypesDao.class);
        registerDaoClass(ServerIpDao.class);
        registerDaoClass(BrandDao.class);
        registerDaoClass(ModelDao.class);
        registerDaoClass(InventoryDetailDao.class);
    }

    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }

    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }

    /**
     * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
     */
    public static abstract class OpenHelper extends DatabaseOpenHelper {
        public OpenHelper(Context context, String name) {
            super(context, name, SCHEMA_VERSION);
        }

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(Database db) {
            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }

    /** WARNING: Drops all table on Upgrade! Use only during development. */
    public static class DevOpenHelper extends OpenHelper {
        public DevOpenHelper(Context context, String name) {
            super(context, name);
        }

        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(Database db, int oldVersion, int newVersion) {
            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }
    }

}
